<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<title>${tagName}</title>
    <link rel="stylesheet" type="text/css" href="${request.contextPath}/resources/css/custag.css">
</head>
<body>
	<div class="address-title">${tagName}</div>
	<div class="address-content">
		<textarea id="answerText" name="answerText" placeholder="${tagName}" maxlength="100" rows="15" class="textarea"></textarea>
		<span class="count-remind">最多100字</span>
	</div>
	<button class="bottom-btn" onclick="saveCusTagAnswer()">确定</button>
</body>
<script src="${request.contextPath}/resources/js/jquery-3.2.1.min.js" type="text/javascript"></script>
<script src="${request.contextPath}/resources/js/layer/layer.js" type="text/javascript"></script>
<script src="${request.contextPath}/resources/js/custag.js" type="text/javascript"></script>
<script type="text/javascript">
	$(function(){
		loadCusTagAnswer();
	});
	//查询数据
	var ids = "";
	function loadCusTagAnswer(){
		$.ajax({
			type: 'post',
	        url: "${request.contextPath}/appapi/getCusTagAnswer",
	        data:{
	            "tagId": "${tagId}",
	            "extId": "${extId}",
	            "customerId": "${customerId}",
	        },
	        dataType: 'json',
	        success: function(data){
	        	if(data.entity == null){
	        		return false;
	        	}
	        	var info = data.entity[0];
	        	ids = info.id;
	        	var tagValue = info.tagValue;
	        	$("#answerText").text(tagValue);
		    }
		});
	}
	//保存答案
	function saveCusTagAnswer(){
		//文本内容
		var answerText = $("#answerText").val();
		if(answerText == ""){
			layer.msg("请填写问题内容");
			return false;
		}
		if(answerText.length > 100){
			layer.msg("问题内容不能超过100个字");
			return false;
		}
	    var json = {
	    	"questionId": "${extId}",
	    	"answerType": "3",
	    	"answerId": "",
	    	"select_other": "",
	    	"answerText": answerText,
	    	"tagId": "${tagId}"
		};
	    var array = new Array();
	    array.push(json);
		//设置遮罩层
		var loadIndex = layer.load(0, {
	        shade: [0.1,'#fff'] //0.1透明度的白色背景
	    });
		//保存问题
		$.ajax({
			type: 'post',
	        url: "${request.contextPath}/appapi/saveCusTagSelect",
	        data:{
	            "customerId": "${customerId}",
	            "userId": "${userId}",
	            "type": "5",
				"json": JSON.stringify(array),
				"ids": ids
	        },
	        dataType: 'json',
	        //async: false,
	        success: function(data){
	        	layer.closeAll('loading'); //关闭加载层
	        	if(data.success == true){
	        		layer.msg("保存成功");
	        		//延时执行执行回调方法并关闭窗口
                    setTimeout("callback()", 1000);
	        	}else{
	        		layer.msg(data.resMsg);
	        	}
	        }
		});
	}
	//返回上一页并刷新页面
	function callback(){
		//ios与安卓分开处理
		var ua = navigator.userAgent;
		if(ua.match(/iPhone|iPod|iPad/i) != null){
			window.location=document.referrer;
		}else{
			history.go(-1);
		}
		return false; 
	}
</script>
</html>